package com.stepcleanse.system.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.stepcleanse.common.log.annotation.Log;
import com.stepcleanse.common.log.enums.BusinessType;
import com.stepcleanse.common.security.annotation.RequiresPermissions;
import com.stepcleanse.system.domain.SellOrder;
import com.stepcleanse.system.service.ISellOrderService;
import com.stepcleanse.common.core.web.controller.BaseController;
import com.stepcleanse.common.core.web.domain.AjaxResult;
import com.stepcleanse.common.core.utils.poi.ExcelUtil;
import com.stepcleanse.common.core.web.page.TableDataInfo;

/**
 * 售卖订单Controller
 * 
 * @author stepcleanse
 * @date 2024-12-09
 */
@RestController
@RequestMapping("/sellorder")
public class SellOrderController extends BaseController
{
    @Autowired
    private ISellOrderService sellOrderService;

    /**
     * 查询售卖订单列表
     */
    @RequiresPermissions("sell:order:list")
    @GetMapping("/list")
    public TableDataInfo list(SellOrder sellOrder)
    {
        startPage();
        List<SellOrder> list = sellOrderService.selectSellOrderList(sellOrder);
        return getDataTable(list);
    }

    /**
     * 导出售卖订单列表
     */
    @RequiresPermissions("sell:order:export")
    @Log(title = "售卖订单", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, SellOrder sellOrder)
    {
        List<SellOrder> list = sellOrderService.selectSellOrderList(sellOrder);
        ExcelUtil<SellOrder> util = new ExcelUtil<SellOrder>(SellOrder.class);
        util.exportExcel(response, list, "售卖订单数据");
    }

    /**
     * 获取售卖订单详细信息
     */
    @RequiresPermissions("sell:order:query")
    @GetMapping(value = "/{orderId}")
    public AjaxResult getInfo(@PathVariable("orderId") String orderId)
    {
        return success(sellOrderService.selectSellOrderByOrderId(orderId));
    }

    /**
     * 新增售卖订单
     */
    @RequiresPermissions("sell:order:add")
    @Log(title = "售卖订单", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody SellOrder sellOrder)
    {
        return toAjax(sellOrderService.insertSellOrder(sellOrder));
    }

    /**
     * 修改售卖订单
     */
    @RequiresPermissions("sell:order:edit")
    @Log(title = "售卖订单", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody SellOrder sellOrder)
    {
        return toAjax(sellOrderService.updateSellOrder(sellOrder));
    }

    /**
     * 删除售卖订单
     */
    @RequiresPermissions("sell:order:remove")
    @Log(title = "售卖订单", businessType = BusinessType.DELETE)
	@DeleteMapping("/{orderIds}")
    public AjaxResult remove(@PathVariable String[] orderIds)
    {
        return toAjax(sellOrderService.deleteSellOrderByOrderIds(orderIds));
    }
}
